<?php

namespace app\company\controller;

use app\BaseController;
use app\company\service\PlatformService;
use app\model\CompanyModel;
use app\model\ConfigModel;
use app\model\ConsultQuestionModel;
use app\model\CrisisBehaviorModel;
use app\model\CrisisLevelModel;
use app\model\CrisisMeasuresModel;
use app\model\CrisisTypeModel;
use app\model\DepartmentLevelModel;
use app\model\DepartmentModel;
use app\model\RoleModel;
use app\model\UnitBannerModel;
use app\model\UnitModel;
use app\model\UserModel;
use think\App;

class Unit extends BaseController
{
    protected $mode;
    public string $message;
    public int $line;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->mode = new UnitModel();
    }

    public function updateRule(): bool|string
    {
        try {
            $param = $this->request->param();
            $this->validate($param,[
                'id|ID' => 'require'
            ]);
            $info = $this->mode->find($param['id']);
            if (!$info) throw new \Exception('参数错误！');
            $info->save($param);
            return success();
        } catch (\Exception $e) {
            return error($e->getMessage(), $e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile(),
            ]);
        }
    }

    /**
     * 获取临时地址
     * @return bool|string
     */
    public function getTemporaryUrl(): bool|string
    {
        try {
            $param = $this->request->param();
            $code = md5('temporaryUrl'.time() . uniqid());
            if (!empty($param['time'])){
                cache($code,[
                    'pc' => '/temporary/pc/index.html',
                    'm' => '/temporary/m/index.html'
                ], intval($param['time']));
            }else{
                cache($code,[
                    'pc' => '/temporary/pc/index.html',
                    'm' => '/temporary/m/index.html'
                ]);
            }
            $CompanyModel = new CompanyModel();
            $login_jump = $CompanyModel->where('id','=',$this->userData['company_id'])->value('login_jump');
            return success('/temporary/'.$code.'/pc/'.$login_jump);
        } catch (\Exception $e) {
            return error($e->getMessage(),$e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    /**
     * 获取系统设置参数
     * @return bool|string
     */
    public function getUnitConfig(): bool|string
    {
        try {
            $param = $this->request->param();
            $this->validate($param, [
                'unit_id|单位ID' => 'require|integer',
                'key|键'  =>  'require',
            ]);
            $ConfigModel = new ConfigModel();
            $data = $ConfigModel->where([
                'unit_id' => $param['unit_id'],
                'key' => $param['key']
            ])->value('value')??'';
            $data = json_decode($data,true);
            return success($data);
        } catch (\Exception $e) {
            return error($e->getMessage(),$e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    /**
     * 部门等级规则列表
     * @return false|string
     */
    public function departmentLevelList(): bool|string
    {
        try {
            $param = $this->request->param();
            $this->validate($param,[
                'unit_id|单位ID' => 'require|integer',
            ]);
            $DepartmentLevelModel = new DepartmentLevelModel();
            $list = $DepartmentLevelModel->where('unit_id','=',$param['unit_id'])->select()->toArray();
            return success($list);
        } catch (\Exception $e) {
            return error($e->getMessage(), $e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    /**
     * 部门选择器
     * @return bool|string
     */
    public function DepartmentSelector(): bool|string
    {
        try {
            $param = $this->request->param();
            $this->validate($param,[
                'unit_id|单位ID' => 'require|integer',
            ]);
            $where = [];
            $where[] = ['unit_id', '=', $param['unit_id']];
            $DepartmentModel = new DepartmentModel();
            $data = $DepartmentModel->where($where)
                ->withCount('users')
                ->withCount('departmentAdmins')
                ->select()->toArray();
            foreach ($data as &$item) {
                $getAllSubcategories = getAllSubcategories($data, $item['id']);
                $users_count = array_column($getAllSubcategories, 'users_count');
                $users_count = array_sum($users_count);
                $item['users_count'] = $item['users_count'] + $users_count;
            }
            return success(['list' => buildTree($data), 'total' => count($data)]);
        } catch (\Exception $e) {
            return error($e->getMessage(), $e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    private string $ruleConfig = '346,347,348,349,350,351,354,355,356,357,360,361,362,363,4,23,51,52,53,54,21,55,56,57,26,58,59,60,35,42,61,62,63,64,65,66,67,68,69,43,70,71,72,73,74,76,79,80,81,82,83,84,85,86,77,87,88,89,90,91,92,93,94,78,95,96,97,98,99,100,101,102,103,104,75,105,106,107,108,109,110,111,120,121,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,157,158,159,160,161,162,165,167,169,171,172,173,175,177,179,182,184,186,188,190,192,194,196,198,201,203,205,207,210,211,213,215,218,220,221,225,226,228,231,233,237,239,240,243,244,246,248,251,253,255,257,259,261,262,264,266,268,270,272,274,276,227,229,245,247,249,250,252,254,256,230,258,294,295,296,260,297,298,299,300,232,263,265,267,269,271,273,275,234,277,279,281,283,285,235,286,287,288,289,290,291,236,238,292,293,241,242,44,47,163,174,176,178,180,181,183,185,187,189,191,193,164,195,197,199,200,202,204,206,208,209,212,214,166,216,217,219,48,168,170,222,224,49,50,14,15,17,19,20,22,24,25,27,28,29,30,18,31,32,33,34,36,37,38,39,40,41,2,3,6,8,9,10,12,13,5,334,335,336,337,338,339,340,341,342,343,344,345,370,371,372,373,374,364,365,366,369';

    /**
     * 单位-左侧选项
     * @return false|string
     */
    public function leftOption(): bool|string
    {
        try {
            $where = [];
            $where[] = ['company_id', '=', $this->userData['company_id']];
            if ($this->userData['type'] == 2){
                switch ($this->userData['level']){
                    case 1:
                        $where[] = ['province_id','=',$this->userData['province_id']];
                        break;
                    case 2:
                        $where[] = ['city_id','=',$this->userData['city_id']];
                        break;
                    case 3:
                        $where[] = ['area_id','=',$this->userData['area_id']];
                        break;
                }
            }
            $data = $this->mode->field('id,level,province_id,city_id,area_id,province_name,city_name,area_name')
                ->where($where)->select()->toArray();
            if (empty($data)) return success();
            $PlatformService = new PlatformService($this->app);
            $data = $PlatformService->leftOption($data);
            if ($this->userData['type'] == 2) {
                switch ($this->userData['level']) {
                    case 2:
                        $data = $data[0]['child'];
                        break;
                    case 3:
                        $data = $data[0]['child'][0]['child'];
                        break;
                }
            }
            return success($data);
        } catch (\Exception $e) {
            return error($e->getMessage(),$e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    /**
     * 单位列表
     * @return false|string
     */
    public function list(): bool|string
    {
        try {
            $param = $this->request->param();
            $where = [];
            $where[] = ['company_id', '=', $this->userData['company_id']];
            if (!empty($param['name'])) {
                $where[] = ['name', 'like', '%' . $param['name'] . '%'];
            }
            if (!empty($param['type'])) {
                if ($param['type'] == 1) {
                    //仅非直属下级单位（非本身）
                    $where[] = ['level', '>', $param['level']];
                }
            } else {
                if (!empty($param['level'])) {
                    $where[] = ['level', '=', $param['level']];
                }
            }
            if (!empty($param['province_id'])) {
                $where[] = ['province_id', '=', $param['province_id']];
            }
            if (!empty($param['city_id'])) {
                $where[] = ['city_id', '=', $param['city_id']];
            }
            if (!empty($param['area_id'])) {
                $where[] = ['area_id', '=', $param['area_id']];
            }
            if ($this->userData['type'] == 2){
                switch ($this->userData['level']){
                    case 1:
                        $where[] = ['province_id','=',$this->userData['province_id']];
                        break;
                    case 2:
                        $where[] = ['city_id','=',$this->userData['city_id']];
                        break;
                    case 3:
                        $where[] = ['area_id','=',$this->userData['area_id']];
                        break;
                }
            }
            $query = $this->mode->where($where);
            $data = $query->order('id desc')->paginate($param['pageSize'])->toArray();
            $data['ids'] = $query->column('id');
            return success($data);
        } catch (\Exception $e) {
            return error($e->getMessage(), $e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile(),
            ]);
        }
    }


    /**
     * 单位详情
     * @return bool|string
     */
    public function info(): bool|string
    {
        try {
            $id = $this->request->param('id');
            $info = $this->mode->find($id);
            if (!$info) throw new \Exception('参数错误！');
            $UserModel = new UserModel();
            //超管账号列表
            $info['user'] = $UserModel->field('id,username,time')
                ->where([
                    ['unit_id', '=', $id],
                    ['role_id', '=', 0]
                ])->select()->toArray();
            return success($info);
        } catch (\Exception $e) {
            return error($e->getMessage(), $e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile(),
            ]);
        }
    }

    /**
     * 添加单位
     * @return bool|string
     */
    public function add(): bool|string
    {
        $this->mode->startTrans();
        try {
            $param = $this->request->param();
            $param['company_id'] = $this->userData['company_id'];
            $this->validate($param, $this->mode->addValidate());
            if ($this->userData['type'] == 2){
                switch ($this->userData['level']){
                    case 1:
                        if ($this->userData['province_id'] != $param['province_id']) throw new \Exception('您没有权限创建该层级单位！');
                        break;
                    case 2:
                        if ($this->userData['city_id'] != $param['city_id']) throw new \Exception('您没有权限创建该层级单位！');
                        break;
                    case 3:
                        if ($this->userData['area_id'] != $param['area_id']) throw new \Exception('您没有权限创建该层级单位！');
                        break;
                }
            }
            $all_name = $this->mode->where('company_id', '=', $this->userData['company_id'])->column('name');
            if (in_array($param['name'],$all_name)) throw new \Exception('单位名称已存在！');
            $param['time'] = time();
            if (isset($param['user'])) {
                $user = $param['user'];
                unset($param['user']);
            }
//            $param['rules'] = $this->ruleConfig;
            $param['areas_id'] = match (intval($param['level'])) {
                1 => $param['province_id'],
                2 => $param['city_id'],
                3 => $param['area_id'],
                default => throw new \Exception('参数错误！'),
            };
            if (empty($param['index_logo'])) {
                $param['index_logo'] = env('SETTING.SOFTWARE_LOGO');
            }
            if (empty($param['logo'])) {
                $param['logo'] = env('SETTING.UNIT_ICON');
            }
            if (empty($param['photo_one'])) {
                $param['photo_one'] = env('SETTING.PHOTO_ONE');
            }
            if (empty($param['photo_two'])) {
                $param['photo_two'] = env('SETTING.PHOTO_TWO');
            }
            if (empty($param['banner'])) {
                $param['banner'] = env('SETTING.PC_BANNER');
            }
            $unit_id = $this->mode->insertGetId($param);
            if (!$this->AddDefaultConfig($unit_id)) throw new \Exception($this->message . $this->line);
            if (isset($user) && count($user) > 0) {
                $admin_save = [];
                $UserModel = new UserModel();
                foreach ($user as $key => $item) {
                    if ($key == 0) {
                        $not_del = 1;
                    } else {
                        $not_del = 0;
                    }
                    $this->validate($item, [
                        'username|账号'  =>  'require|length:8,18|alphaNum',
                        'password|密码'  =>  'require|length:8,18',
                    ],[
                        'username.require' => '账号不能为空',
                        'username.length'     => '账号长度不符合要求，8-18位字符',
                        'username.alphaNum'     => '账号格式不符合要求，字母或数字',
                        'password.require'        => '密码不能为空',
                        'password.length'        => '密码长度不符合要求，8-18位字符',
                    ]);
                    $admin_save[] = [
                        'company_id' => $this->userData['company_id'],
                        'areas_id' => $param['areas_id'],
                        'unit_id' => $unit_id,
                        'name' => '超级管理员',
                        'type' => 3,
                        'username' => $item['username'],
                        'password' => encrypt_password($item['password']),
                        'avatar' => '/user_avatar/admin.png',
                        'level' => $param['level'],
                        'province_id' => $param['province_id'],
                        'city_id' => $param['city_id'],
                        'area_id' => $param['area_id'],
                        'province_name' => $param['province_name'],
                        'city_name' => $param['city_name'],
                        'area_name' => $param['area_name'],
                        'time' => $item['time'],
                        'not_del' => $not_del,
                    ];
                }
                $usernameData = array_column($admin_save, 'username');
                $uid = $UserModel->where('username', 'in', $usernameData)->value('id');
                if ($uid) throw new \Exception('账号已存在！');
                $UserModel->insertAll($admin_save);
            }
            $this->mode->commit();
            return success([], '添加成功！');
        } catch (\Exception $e) {
            $this->mode->rollback();
            return error($e->getMessage(), 0, [
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    /**
     * 编辑单位
     * @return false|string
     */
    public function update(): bool|string
    {
        try {
            $param = $this->request->param();
            $this->validate($param,[
                'id|ID' => 'require|integer',
                'province_id|省ID' => 'require|integer',
                'city_id|市ID' => 'require|integer',
                'area_id|区ID' => 'require|integer',
                'level|层级' => 'require|in:1,2,3',
                'user|账号' => 'require',
            ]);
            if ($this->userData['type'] == 2){
                switch ($this->userData['level']){
                    case 1:
                        if ($this->userData['province_id'] != $param['province_id']) throw new \Exception('您没有权限创建该层级单位！');
                        break;
                    case 2:
                        if ($this->userData['city_id'] != $param['city_id']) throw new \Exception('您没有权限创建该层级单位！');
                        break;
                    case 3:
                        if ($this->userData['area_id'] != $param['area_id']) throw new \Exception('您没有权限创建该层级单位！');
                        break;
                }
            }
            $info = $this->mode->find($param['id']);
            if (!$info) throw new \Exception('参数错误！');
            $param['areas_id'] = match (intval($param['level'])) {
                1 => $param['province_id'],
                2 => $param['city_id'],
                3 => $param['area_id'],
                default => throw new \Exception('参数错误！'),
            };
            $UserModel = new UserModel();
            if (isset($param['user'])) {
                $admin_save = [];
                $usernameData = [];
                foreach ($param['user'] as $item) {
                    $this->validate($item, [
                        'username|账号' => 'require|length:8,18|alphaNum',
                    ], [
                        'username.require' => '账号不能为空',
                        'username.length' => '账号长度不符合要求，8-18位字符',
                        'username.alphaNum' => '账号格式不符合要求，字母或数字',
                    ]);
                    $userInfo = [
                        'company_id' => $this->userData['company_id'],
                        'areas_id' => $param['areas_id'],
                        'unit_id' => $param['id'],
                        'username' => $item['username'],
                        'name' => '超级管理员',
                        'type' => 3,
                        'level' => $param['level'],
                        'province_id' => $param['province_id'],
                        'city_id' => $param['city_id'],
                        'area_id' => $param['area_id'],
                        'province_name' => $param['province_name'],
                        'city_name' => $param['city_name'],
                        'area_name' => $param['area_name'],
                    ];
                    if (!empty($item['id'])) {
                        if (!empty($item['password'])) {
                            $this->validate($item, [
                                'password|密码' => 'require|length:8,18',
                            ], [
                                'password.require' => '密码不能为空',
                                'password.length' => '密码长度不符合要求，8-18位字符',
                            ]);
                            $userInfo['password'] = encrypt_password($item['password']);
                        }
                        $userInfo['id'] = $item['id'];
                        if (!empty($param['del']) && in_array($item['id'], $param['del'])) {
                            $param['del'] = array_diff($param['del'], [$item['id']]);
                            $userInfo['is_del'] = 1;
                            $userInfo['del_time'] = time();
                        }
                    } else {
                        $this->validate($item, [
                            'password|密码' => 'require|length:8,18',
                        ], [
                            'password.require' => '密码不能为空',
                            'password.length' => '密码长度不符合要求，8-18位字符',
                        ]);
                        $userInfo['password'] = encrypt_password($item['password']);
                        $userInfo['avatar'] = '/user_avatar/admin.png';
                        $userInfo['time'] = time();
                        $usernameData[] = $item['username'];
                    }
                    $admin_save[] = $userInfo;
                }
                if (!empty($admin_save)) {
                    if (!empty($usernameData)) {
                        $uid = $UserModel->where('username', 'in', $usernameData)->value('id');
                        if ($uid) throw new \Exception('账号已存在！');
                    }
                    $UserModel->saveAll($admin_save);
                }
                unset($param['user']);
            }
            if (isset($param['del'])) {
                if (!empty($param['del'])) {
                    $UserModel->where('id', 'in', $param['del'])->update([
                        'is_del' => 1,
                        'del_time' => time()
                    ]);
                }
                unset($param['del']);
            }
            $info->save($param);
            return success([], '更新成功！');
        } catch (\Exception $e) {
            return error($e->getMessage(), $e->getCode(), [
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    /**
     * 删除单位
     * @return false|string
     */
    public function del(): bool|string
    {
        $id = $this->request->param('id');
        try {
            $id = explode(',', $id);
            if (is_array($id)) {
                $where[] = ['id', 'in', $id];
            } else {
                $where[] = ['id', '=', $id];
            }
            $this->mode->where($where)->update([
                'is_del' => 1,
                'del_time' => time()
            ]);
            return success([], '删除成功！');
        } catch (\Exception $e) {
            return error($e->getMessage(), $e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile(),
            ]);
        }
    }

    /**
     * 封停单位
     * @return false|string
     */
    public function status(): bool|string
    {
        $id = $this->request->param('id');
        $status = $this->request->param('status');
        try {
            $id = explode(',', $id);
            if (is_array($id)) {
                $where[] = ['id', 'in', $id];
            } else {
                $where[] = ['id', '=', $id];
            }
            $this->mode->where($where)->update([
                'status' => $status,
            ]);
            return success([], '修改成功！');
        } catch (\Exception $e) {
            return error($e->getMessage(), $e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile(),
            ]);
        }
    }

    /**
     * 获取上级信息
     * @return false|string
     */
    public function getSuperiorInfo(): bool|string
    {
        try {
            $param = $this->request->param();
            $PlatformService = new PlatformService($this->app);
            return success($PlatformService->unitSuperiorInfo($this->userData['company_id'], $param));
        } catch (\Exception $e) {
            return error($e->getMessage(), $e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile(),
            ]);
        }
    }


    /**
     * 更新模块权限
     * @return false|string
     */
    public function updateRules(): bool|string
    {
        try {
            $param = $this->request->param();
            $this->validate($param,[
                'id|ID' => 'require',
                'rules|权限' => 'require'
            ]);
            $id = explode(',', $param['id']);
            if (is_array($id)) {
                $where[] = ['id', 'in', $id];
            } else {
                $where[] = ['id', '=', $id];
            }
            $rules = explode(',', $param['rules']);
            $rules = implode(',', PlatformService::AssignPermissions($rules));
            $this->mode->where($where)->update(['rules' => $rules]);
            return success([], '更新成功！');
        } catch (\Exception $e) {
            return error($e->getMessage(), $e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile(),
            ]);
        }
    }

    /**
     * 继承上级权限
     * @return false|string
     */
    public function inheritRules(): bool|string
    {
        $this->mode->startTrans();
        try {
            $id = $this->request->param('id');
            $id = explode(',', $id);
            $PlatformService = new PlatformService($this->app);
            if (is_array($id)) {
                foreach ($id as $v) {
                    $info = $this->mode->find($v);
                    //上级信息
                    $superiorInfo = $PlatformService->unitSuperiorInfo($this->userData['company_id'], [
                        'level' => $info['level'],
                        'province_id' => $info['province_id'],
                        'city_id' => $info['city_id'],
                        'area_id' => $info['area_id'],
                    ]);
                    $this->mode->where('id', '=', $v)->update(['rules' => $superiorInfo['rules']]);
                }
            } else {
                $info = $this->mode->find($id);
                //上级信息
                $superiorInfo = $PlatformService->unitSuperiorInfo($this->userData['company_id'], [
                    'level' => $info['level'],
                    'province_id' => $info['province_id'],
                    'city_id' => $info['city_id'],
                    'area_id' => $info['area_id'],
                ]);
                $this->mode->where('id', '=', $id)->update(['rules' => $superiorInfo['rules']]);
            }
            $this->mode->commit();
            return success([], '继承成功！');
        } catch (\Exception $e) {
            $this->mode->rollback();
            return error($e->getMessage(), $e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile(),
            ]);
        }
    }


    /**
     * role默认权限配置
     * @param int $mode
     * @return string
     */
    public function roleRulesConfig(int $mode): string
    {
        $data = [
            0 => '346,347,348,349,350,351,354,355,356,357,360,361,362,363,4,23,51,52,53,54,21,55,56,57,26,58,59,60,35,42,61,62,63,64,65,66,67,68,69,43,70,71,72,73,74,76,79,80,81,82,83,84,85,86,77,87,88,89,90,91,92,93,94,78,95,96,97,98,99,100,101,102,103,104,75,105,106,107,108,109,110,111,120,121,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,157,158,159,160,161,162,165,167,169,171,172,173,175,177,179,182,184,186,188,190,192,194,196,198,201,203,205,207,210,211,213,215,218,220,221,225,226,228,231,233,237,239,240,243,244,246,248,251,253,255,257,259,261,262,264,266,268,270,272,274,276,227,229,245,247,249,250,252,254,256,230,258,294,295,296,260,297,298,299,300,232,263,265,267,269,271,273,275,234,277,279,281,283,285,235,286,287,288,289,290,291,236,238,292,293,241,242,44,47,163,174,176,178,180,181,183,185,187,189,191,193,164,195,197,199,200,202,204,206,208,209,212,214,166,216,217,219,48,168,170,222,224,49,50,14,15,17,19,20,22,24,25,27,28,29,30,18,31,32,33,34,36,37,38,39,40,41,2,3,6,8,9,10,12,13,5,334,335,336,337,338,339,340,341,342,343,344,345,370,371,372,373,374,364,365,366,369',
            1 => '4,23,21,55,56,57,73,74,78,95,96,97,98,99,100,101,102,103,104,75,105,106,107,108,121,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,157,158,159,160,161,162,165,167,169,171,172,173,175,177,179,182,184,186,188,190,192,194,196,198,201,205,207,213,215,218,220,221,228,231,233,237,239,240,243,244,246,248,251,253,255,257,259,261,262,264,266,268,270,272,274,276,227,229,245,247,249,250,252,254,256,230,258,294,295,296,260,232,263,271,275,234,277,281,285,235,290,236,238,292,293,241,242,44,47,163,174,178,191,193,164,195,199,212,214,166,216,48,168,49,50,14,15,17,19,24,25,27,28,29,30,18,31,37,38,39,40,41,2,3,10,5',
            2 => '14,15,17,19,24,25,27,28,29,30,18,31,37,38,39,40,41,44,47,163,174,176,178,180,181,183,185,187,189,191,193,164,195,197,199,200,202,204,206,208,209,212,214,166,216,217,219,48,168,170,222,224,49,50,227,229,245,247,249,250,252,254,256,230,258,260,232,263,234,277,121,129,130,131,133,135,136,140,141,143,145,146,150,151,153,155,160,161,165,169,171,177,179,184,188,190,198,201,203,205,207,210,211,213,215,105,106,107,108,124,125,126,127,128,218,220,221,225,226,228,231,233',
            3 => '105,106,107,108,309,120,121,122,123,129,130,131,132,136,137,301,140,141,142,146,147,302,160,161,162,171,172,303,227,236,44,45,46,47,163,174,176,189,164,195,197,209,304'
        ];
        return $data[$mode];
    }

    /**
     * 添加单位默认配置
     * @param $unit_id
     * @return int
     */
    public function AddDefaultConfig($unit_id): int
    {
        try {
            $time = time();
            //默认学制阶段
            $DepartmentLevelModel = new DepartmentLevelModel();
            $department_level[] = [
                'unit_id' => $unit_id,
                'name' => '九年义务教育',
                'level_rules' => json_encode(["一年级","二年级","三年级","四年级","五年级","六年级","七年级","八年级","九年级"]),
                'time' => $time
            ];
            $department_level[] = [
                'unit_id' => $unit_id,
                'name' => '高中',
                'level_rules' => json_encode(["高中一年级","高中二年级","高中三年级"]),
                'time' => $time
            ];
            $department_level[] = [
                'unit_id' => $unit_id,
                'name' => '大学',
                'level_rules' => json_encode(["大学一年级","大学二年级","大学三年级","大学四年级"]),
                'time' => $time
            ];
            $DepartmentLevelModel->insertAll($department_level);
            //默认手机端banner
            $UnitBannerModel = new UnitBannerModel();
            $UnitBannerModel->insert([
                'unit_id' => $unit_id,
                'type' => 2,
                'img' => env('SETTING.RATING_MOBILE_BANNER'),
                'time' => $time
            ]);
            //咨询问题类型
            $ConsultQuestionData = ['个人成长', '恋爱情感', '家庭关系', '职业发展', '人际交往', '情绪危机', '烦恼忧愁', '其他问题'];
            $ConsultQuestionAdd = [];
            foreach ($ConsultQuestionData as $value) {
                $ConsultQuestionAdd[] = [
                    'unit_id' => $unit_id,
                    'name' => $value,
                    'status' => 1,
//                    'time' => $time
                ];
            }
            if (!empty($ConsultQuestionAdd)) {
                $ConsultQuestionModel = new ConsultQuestionModel();
                $ConsultQuestionModel->insertAll($ConsultQuestionAdd);
            }
            //危机干预类型
            $crisisData = [
                'type' => [
                    'CrisisMeasures', 'CrisisType', 'CrisisBehavior', 'CrisisLevel',
                ],
                'content' => [
                    ['重点关注', '心理咨询', '门诊治疗', '住院治疗', '请假休息', '24小时监护', '管理员约谈', '他人谈心',],
                    ['学习压力', '就业压力', '人际沟通', '恋爱问题', '睡眠障碍', '环境不适', '认知差错', '焦虑不安', '家庭关系', '强迫症', '攻击性表现', '精神幻觉'],
                    ['无异常表现', '双相情感障碍', '抑郁症', '焦虑症', '强迫症', '睡眠障碍', '进食障碍', '成瘾障碍', '创伤及应急障碍', '人格障碍', '精神分裂症'],
                    ['一级', '二级', '三级', '四级', '五级',],
                ],
                'remark' => [
                    [
                        '', '', '', '', '', '', '', '', '', '', '',
                    ],
                    [
                        '人在学习活动中所承受的精神负担',
                        '为获得职业做准备及在寻求职业的过程中面对具有威胁性、挑战性刺激时所产生的一种被压迫的感受',
                        '通过一定的语言、文字或肢体动作、表情等表达某种信息传递给其他个体的过程',
                        '包括：依赖型恋爱障碍、恐惧型恋爱障碍、自卑型恋爱障碍',
                        '睡眠量不正常以及睡眠中出现异常行为的表现',
                        '进入一个新的环境,无法轻松地适应并无法达到平衡状态的情况',
                        '知觉自身、他人或外部环境时,常因自身或情境的原因使得知觉结果出现失真的现象',
                        '缺乏明显客观原因的内心不安或无根据的恐惧',
                        '家庭出现成员关系不睦、教养方式偏差等问题',
                        '一种反复持久出现的强迫观念、行为或者仪式动作',
                        '有意挑衅、侵犯或对事物有意损毁、破坏等心理倾向和行为',
                        '感到脑内有无形文字、无声言语，内容不属于自己，也不能由主观意志改变',
                    ],
                    [
                        '指从表像上看不出异常行为。',
                        '又叫双相障碍，是一类既有躁狂发作或者轻躁狂发作，又有抑郁发作（典型特征）的常见精神障碍。',
                        '最常见的精神障碍，核心症状是显著持久的情绪低落、兴趣减退等，部分患者有存在自伤、自杀行为，可伴有妄想、幻觉等精神病性症状，严重时可能发生抑郁性木僵，可表现为面部表情固定、对刺激缺乏反应、话少甚至不言语、少动甚至不动等。',
                        '主要表现为：无明确客观对象的紧张担心，坐立不安，还有植物神经功能失调症状，如心悸、手抖、出汗、尿频，及运动性不安等。',
                        '一些毫无意义、甚至违背自己意愿的想法或冲动反反复复侵入患者的日常生活。这些想法来源于自身，极力抵抗，但始终无法控制，强烈的冲突使其感到巨大的焦虑和痛苦，影响学习工作、人际交往甚至生活起居。',
                        '睡眠障碍，主要临床表现为入睡困难、睡眠维持困难、早醒而引起的睡眠满意度下降。可由不愉快心理事件、不舒适的外界环境引起。',
                        '指以进食行为异常、对食物及体重和体型的过分关注为主要临床特征的一组疾病。害怕和试图抵消食物的‘发胖’作用常常是多数患者最明显的心理病理。',
                        '指个人对某种物质或行为产生了强烈的欲望和依赖，不能自律地控制行为，甚至带来严重的生理和心理问题。成瘾障碍可以包括物质成瘾（如酒精、烟草、毒品等）和行为成瘾（如赌博、游戏、网络等）。',
                        '创伤后应激障碍（ PTSD）是指个体经历、目睹或遭遇到一个或多个涉及自身或他人的实际死亡，或受到死亡的威胁，或严重的受伤，或躯体完整性受到威胁后，所导致的个体延迟出现和持续存在的精神障碍',
                        '是在个体发育成长过程中，因遗传、先天以及后天不良环境因素造成的个体心理与行为的持久性的固定行为模式，这种行为模式偏离社会文化背景，并给个体自身带来痛苦，或贻害周围。',
                        '精神分裂症，定义为一种慢性的精神障碍，包括个人的感知觉、情感与行为的异常。患者很难区分出真实和想象，患者反应迟钝、行为退缩或过激，严重者难以进行正常社交。',
                    ],
                    ['抑郁程度', '自残风险程度', '自杀风险程度', '攻击他人风险程度', '有破坏行为程序'],
                ],
            ];
            for ($i = 0; $i < count($crisisData['type']); $i++) {
                $typeDate = [];
                $content = $crisisData['content'][$i];
                $remark = $crisisData['remark'][$i];
                foreach ($content as $k => $v) {
                    $typeDate[$k]['unit_id'] = $unit_id;
//                    $typeDate[$k]['uid'] = $this->userData['id'];
                    $typeDate[$k]['name'] = $v;
                    $typeDate[$k]['explain'] = $remark[$k] ?? '';
                    $typeDate[$k]['status'] = 1;
//                    $typeDate[$k]['time'] = $time;
                }
                switch ($crisisData['type'][$i]) {
                    case 'CrisisMeasures':
                        $CrisisMeasuresModel = new CrisisMeasuresModel();
                        $CrisisMeasuresModel->insertAll($typeDate);
                        break;
                    case 'CrisisType':
                        $CrisisTypeModel = new CrisisTypeModel();
                        $CrisisTypeModel->insertAll($typeDate);
                        break;
                    case 'CrisisBehavior':
                        $CrisisBehaviorModel = new CrisisBehaviorModel();
                        $CrisisBehaviorModel->insertAll($typeDate);
                        break;
                    case 'CrisisLevel':
                        $CrisisLevelModel = new CrisisLevelModel();
                        $CrisisLevelModel->insertAll($typeDate);
                        break;
                    default:
                        break;
                }
            }
            //默认角色
            $roleData = [];
            $roleMode = [1, 2, 3];
            foreach ($roleMode as $v) {
                $roleData[] = [
                    'unit_id' => $unit_id,
                    'name' => match ($v) {
                        1 => '管理员',
                        2 => '咨询师',
                        3 => '普通用户'
                    },
                    'mode' => $v,
                    'rules' => $this->roleRulesConfig($v) ?? '',
                    'time' => $time
                ];
            }
            $RoleModel = new RoleModel();
            $RoleModel->insertAll($roleData);
            //配置
            $data = [
                [
                    'unit_id' => $unit_id,
                    'key' => 'department_push_message',
                    'value' => '{"fail":"1","fail_num":"3","interval_time":"10","channels":["1","2","3"]}',
                    'explain' => '推送消息设置',
                    'time' => $time
                ], [
                    'unit_id' => $unit_id,
                    'key' => 'evaluation_task',
                    'value' => '{"is_introduction":"1","is_authorize":"1","is_identity_selection":"1","identity_type":"1","is_continuous":"1","is_redo":"1","expire_task":"1","is_reminder":"0","is_temporary":"1","reminder":"", "is_voice": "1","reminder_channel":["2"],"code_valid":0}',
                    'explain' => '测评任务设置',
                    'time' => $time
                ], [
                    'unit_id' => $unit_id,
                    'key' => 'evaluation_report',
                    'value' => '{"is_notice":"1","notice_type":["1"],"is_explain":"1","explain_num":"1","explain_price":"0","is_del":"1","warning_report":"0","export_style":"0","export_format":"0","print_paper":"4","is_user_info":"0","self_evaluate_jurisdiction":["1","2","3","4"],"version_report":0}',
                    'explain' => '测评报告设置',
                    'time' => $time
                ], [
                    'unit_id' => $unit_id,
                    'key' => 'department_management',
                    'value' => '{"type":"1","upgrade_time_month":"9","upgrade_time_day":"1","end_status":"2"}',
                    'explain' => '部门管理方式设置',
                    'time' => $time
                ], [
                    'unit_id' => $unit_id,
                    'key' => 'consult',
                    'value' => '{"in_advance":"1","in_advance_time":"1","remove_restrictions":"0","is_remind":"1","is_address":"0","contract":"         \u6839\u636e\u56fd\u5bb6\u76f8\u5173\u6cd5\u5f8b\u6cd5\u89c4\uff0c\u4e3a\u4fdd\u969c\u54a8\u8be2\u6548\u679c\uff0c\u5728\u8bda\u5b9e\u5b88\u4fe1\u3001\u76f8\u4e92\u5c0a\u91cd\u3001\u76f8\u4e92\u4fe1\u4efb\u3001\u5e73\u7b49\u81ea\u613f\u3001\u534f\u5546\u4e00\u81f4\u7684\u524d\u63d0\uff0c\u672c\u5e73\u53f0\u54a8\u8be2\u5e08\u6839\u636e\u300a\u4e2d\u534e\u4eba\u6c11\u5171\u548c\u56fd\u5fc3\u7406\u54a8\u8be2\u5e08\u804c\u4e1a\u6807\u51c6\u300b\u4ee5\u53ca\u670d\u52a1\u884c\u4e1a\u7684\u901a\u7528\u6cd5\u5f8b\u6cd5\u89c4\u4e3a\u4e59\u65b9\u63d0\u4f9b\u5fc3\u7406\u54a8\u8be2\u670d\u52a1\u3002\u5c31\u5fc3\u7406\u54a8\u8be2\u5177\u4f53\u4e8b\u9879\u4e0e\u7528\u6237\u8fbe\u6210\u5982\u4e0b\u534f\u8bae\uff1a\n         \u4e00\u3001\u826f\u597d\u7684\u5fc3\u7406\u54a8\u8be2\u6548\u679c\u662f\u5efa\u7acb\u5728\u53cc\u65b9\u76f8\u4e92\u9ad8\u5ea6\u5c0a\u91cd\u4e0e\u4fe1\u4efb\u7684\u57fa\u7840\u4e0a\u3002\u54a8\u8be2\u65f6\uff0c\u7528\u6237\u6709\u8d23\u4efb\u5411\u54a8\u8be2\u5e08\u5982\u5b9e\u8be6\u5c3d\u63d0\u4f9b\u4e2a\u4eba\u76f8\u5173\u8d44\u6599\uff0c\u7531\u4e8e\u7528\u6237\u6545\u610f\u9690\u7792\u6216\u8005\u626d\u66f2\u8d44\u6599\u800c\u9020\u6210\u7684\u4e0d\u826f\u540e\u679c\u7531\u7528\u6237\u81ea\u8eab\u8d1f\u8d23\u3002\n         \u4e8c\u3001\u53cc\u65b9\u5728\u6bcf\u6b21\u54a8\u8be2\u524d\u5747\u8981\u505a\u597d\u51c6\u5907\u5de5\u4f5c\uff0c\u53cc\u65b9\u5728\u54a8\u8be2\u540e\u5e94\u53ca\u65f6\u4ea4\u6d41\u54a8\u8be2\u611f\u53d7\uff0c\u4ee5\u4fbf\u8c03\u6574\u54a8\u8be2\u65b9\u6848\u4e0e\u8fdb\u7a0b\u3002\n         \u4e09\u3001\u7528\u6237\u5e94\u8ba4\u771f\u914d\u5408\u54a8\u8be2\u5e08\u586b\u5199\u5fc3\u7406\u54a8\u8be2\u8bb0\u5f55\u3002\n         \u56db\u3001\u54a8\u8be2\u65b9\u6848\u4ee5\u53cc\u65b9\u8bae\u5b9a\u4e3a\u51c6\u3002\u4efb\u4f55\u4e00\u65b9\u5728\u5177\u4f53\u4fee\u6539\u65b9\u6848\u65f6\uff0c\u5747\u5e94\u5f97\u5230\u53e6\u4e00\u65b9\u7684\u540c\u610f\u3002\u54a8\u8be2\u65b9\u6848\u786e\u5b9a\u540e\uff0c\u54a8\u8bbf\u53cc\u65b9\u5e94\u6309\u7ea6\u5b9a\u5c65\u884c\u5404\u81ea\u7684\u914d\u5408\u534f\u4f5c\u4e49\u52a1\uff0c\u4ee5\u4fdd\u8bc1\u54a8\u8be2\u6548\u679c\u3002\n         \u4e94\u3001\u54a8\u8be2\u5e08\u6709\u8d23\u4efb\u4e3a\u7528\u6237\u63d0\u4f9b\u7684\u8d44\u6599\u4fdd\u5bc6\u3002\u5982\u54a8\u8be2\u5e08\u5c06\u7528\u6237\u63d0\u4f9b\u7684\u8d44\u6599\u7528\u4e8e\u5bf9\u7528\u6237\u8fdb\u884c\u5fc3\u7406\u54a8\u8be2\u4e4b\u5916\u7684\u5176\u4ed6\u7528\u9014\uff0c\u987b\u5f81\u5f97\u7528\u6237\u7684\u540c\u610f\uff0c\u672a\u5f81\u5f97\u7528\u6237\u540c\u610f\u800c\u9020\u6210\u7684\u4e0d\u826f\u540e\u679c\u7531\u54a8\u8be2\u5e08\u8d1f\u8d23\u3002\n         \u516d\u3001\u5fc3\u7406\u54a8\u8be2\u670d\u52a1\u5f00\u59cb\u540e\uff0c\u54a8\u8be2\u5e08\u987b\u4e3a\u7528\u6237\u63d0\u4f9b\u4e13\u4e1a\u3001\u6709\u6548\u7684\u54a8\u8be2\uff0c\u7528\u6237\u5728\u54a8\u8be2\u4e2d\u9700\u79ef\u6781\u914d\u5408\u54a8\u8be2\u5e08\uff0c\u53cc\u65b9\u987b\u76f8\u4e92\u652f\u6301\u3001\u76f8\u4e92\u5c0a\u91cd\u3002\u53cc\u65b9\u987b\u9075\u5b88\u5728\u5fc3\u7406\u54a8\u8be2\u524d\u548c\u54a8\u8be2\u8fc7\u7a0b\u4e2d\u8fbe\u6210\u7684\u53e3\u5934\u6216\u8005\u4e66\u9762\u7ea6\u5b9a\u3002\u5982\u7528\u6237\u6709\u65e0\u6545\u7f3a\u5e2d\u3001\u8fdf\u5230\u3001\u65e9\u9000\u3001\u4e0d\u8ba4\u771f\u5b8c\u6210\u5fc3\u7406\u54a8\u8be2\u6240\u8981\u6c42\u5b8c\u6210\u7684\u5bb6\u5ead\u4f5c\u4e1a\u3001\u6545\u610f\u5201\u96be\u5fc3\u7406\u54a8\u8be2\u4eba\u5458\u7b49\u7834\u574f\u54a8\u8be2\u5173\u7cfb\u7684\u8a00\u884c\uff0c\u5176\u9020\u6210\u7684\u540e\u679c\u7531\u7528\u6237\u8d1f\u8d23\uff1a\u5982\u7531\u4e8e\u54a8\u8be2\u5e08\u7684\u5fc3\u7406\u54a8\u8be2\u64cd\u4f5c\u6709\u8bef\u6216\u8a00\u884c\u4e0d\u826f\uff0c\u5176\u9020\u6210\u7684\u540e\u679c\u7531\u54a8\u8be2\u5e08\u8d1f\u8d23\u3002\n         \u4e03\u3001\u53cc\u65b9\u534f\u5546\u786e\u5b9a\u7684\u5fc3\u7406\u54a8\u8be2\u670d\u52a1\u65b9\u5f0f\u4e3a\u7ebf\u4e0a\u63d0\u4f9b\u54a8\u8be2\u670d\u52a1\u4ee5\u53ca\u7ebf\u4e0b\u63d0\u4f9b\u9884\u7ea6\u670d\u52a1\u3002\u7ebf\u4e0a\u54a8\u8be2\u53ef\u968f\u65f6\u5728\u5e73\u53f0\u5185\u53d1\u8d77\uff0c\u7ebf\u4e0b\u9884\u7ea6\u9700\u5728\u5e73\u53f0\u5185\u63d0\u524d\u9884\u7ea6\u3002\u7528\u6237\u5728\u6bcf\u6b21\u7ebf\u4e0b\u9884\u7ea6\u540e\u9700\u6309\u65f6\u63a5\u53d7\u5fc3\u7406\u54a8\u8be2\u670d\u52a1\u3002\u5982\u53cc\u65b9\u4e2d\u7684\u4efb\u4f55\u4e00\u65b9\u5982\u6709\u7279\u6b8a\u60c5\u51b5\uff0c\u9700\u53d8\u66f4\u54a8\u8be2\u65f6\u95f4\uff0c\u9700\u901a\u8fc7\u7535\u8bdd\u3001\u77ed\u4fe1\u3001\u5e73\u53f0\u53d6\u6d88\u9884\u7ea6\u7b49\u65b9\u5f0f\uff0c\u81f3\u5c11\u63d0\u524d\u4e24\u5c0f\u65f6\u901a\u77e5\u5bf9\u65b9\u3002\u53cc\u65b9\u4e2d\u7684\u4efb\u4f55\u4e00\u65b9\u5728\u51b3\u5b9a\u63d0\u524d\u9000\u51fa\u54a8\u8be2\u3001\u6682\u505c\u6216\u7ec8\u6b62\u54a8\u8be2\u65f6\uff0c\u987b\u5411\u53e6\u4e00\u65b9\u8bf4\u660e\u539f\u56e0\u3002\n         \u516b\u3001\u7528\u6237\u987b\u4fdd\u8bc1\u5728\u63a5\u53d7\u5fc3\u7406\u54a8\u8be2\u671f\u95f4\u4e0d\u53d1\u751f\u4efb\u4f55\u6545\u610f\u4f24\u5bb3\u81ea\u5df1\u6216\u6545\u610f\u5371\u5bb3\u4ed6\u4eba\u4eba\u8eab\u5b89\u5168\u7684\u884c\u4e3a\u3002\u7528\u6237\u5982\u60a3\u6709\u81ea\u4f24\u3001\u81ea\u6740\u6216\u4f24\u5bb3\u4ed6\u4eba\u5371\u9669\u7684\u5fc3\u7406\u969c\u788d\u6216\u5fc3\u7406\u75be\u75c5\uff0c\u54a8\u8be2\u5e08\u53ca\u5e73\u53f0\u4e0d\u5bf9\u7528\u6237\u53ef\u80fd\u4ea7\u751f\u7684\u4e0a\u8ff0\u540e\u679c\u627f\u62c5\u4efb\u4f55\u8d23\u4efb\u3002\n         \u4e5d\u3001\u6709\u81ea\u6740\u503e\u5411\u6216\u81ea\u6740\u672a\u9042\u7684\u884c\u4e3a\u7684\u6765\u8bbf\u8005\u524d\u6765\u54a8\u8be2\u65f6\uff0c\u54a8\u8be2\u5e08\u4f1a\u5c3d\u91cf\u4e3a\u6765\u8bbf\u8005\u63d0\u4f9b\u5e2e\u52a9\u3002\u5982\u6765\u8bbf\u8005\u7ecf\u8fc7\u54a8\u8be2\u540e\u4ecd\u7136\u6700\u7ec8\u9009\u62e9\u4e86\u81ea\u6740\uff0c\u8d23\u4efb\u53ca\u884c\u4e3a\u540e\u679c\u5c06\u7531\u6765\u8bbf\u8005\u672c\u4eba\u5168\u90e8\u627f\u62c5\u3002\u672c\u5e73\u53f0\u53ca\u54a8\u8be2\u5e08\u4e0d\u627f\u62c5\u4efb\u4f55\u8d23\u4efb\u3002\n         \u5341\u3001\u5728\u7528\u6237\u81ea\u613f\u5e76\u7559\u4e0b\u771f\u5b9e\u3001\u6709\u6548\u7684\u8054\u7cfb\u65b9\u5f0f\u7684\u524d\u63d0\u4e0b\uff0c\u5141\u8bb8\u54a8\u8be2\u5e08\u5bf9\u7528\u6237\u901a\u8fc7\u7535\u8bdd\u3001\u77ed\u4fe1\u3001\u7535\u5b50\u90ae\u4ef6\u7b49\u65b9\u5f0f\u8fdb\u884c\u56de\u8bbf\uff0c\u4e86\u89e3\u54a8\u8be2\u7684\u4e2d\u957f\u671f\u6548\u679c\uff0c\u5e2e\u52a9\u7528\u6237\u4fdd\u7279\u957f\u4e45\u7684\u5fc3\u7406\u5065\u5eb7\u3002\n         \u5341\u4e00\u3001\u7528\u6237\u7684\u8d23\u4efb\u6743\u529b\u4e49\u52a1\uff1a\n\u8d23\u4efb\uff1a\n(1)\u5411\u54a8\u8be2\u5e08\u63d0\u4f9b\u4e0e\u5fc3\u7406\u95ee\u9898\u6709\u5173\u7684\u771f\u5b9e\u8d44\u6599\uff1b\n(2)\u79ef\u6781\u4e3b\u52a8\u5730\u4e0e\u54a8\u8be2\u5e08\u4e00\u8d77\u63a2\u7d22\u89e3\u51b3\u95ee\u9898\u7684\u65b9\u6cd5\uff1b\n(3)\u5b8c\u6210\u53cc\u65b9\u5546\u5b9a\u7684\u4f5c\u4e1a\u3002\n\u6743\u529b\uff1a\n(1)\u6709\u6743\u529b\u4e86\u89e3\u54a8\u8be2\u5e08\u7684\u53d7\u8bad\u80cc\u666f\u548c\u6267\u4e1a\u8d44\u683c\uff1b\n(2)\u6709\u6743\u529b\u4e86\u89e3\u54a8\u8be2\u7684\u5177\u4f53\u65b9\u6cd5\u8fc7\u7a0b\u539f\u7406\uff1b\n(3)\u6709\u6743\u529b\u9009\u62e9\u6216\u8005\u66f4\u6362\u5408\u9002\u7684\u54a8\u8be2\u5e08\uff1b\n(4)\u6709\u6743\u529b\u63d0\u51fa\u8f6c\u4ecb\u6216\u8005\u4e2d\u6b62\u54a8\u8be2\uff1b\n(5)\u5bf9\u54a8\u8be2\u65b9\u6848\u5730\u5185\u5bb9\u6709\u77e5\u60c5\u6743\u3001\u534f\u5546\u6743\u548c\u9009\u62e9\u6743\u3002\n\u4e49\u52a1\uff1a\n(1)\u9075\u5b88\u54a8\u8be2\u673a\u6784\u5730\u76f8\u5173\u89c4\u5b9a\uff1b\n(2)\u9075\u5b88\u548c\u6267\u884c\u5546\u5b9a\u597d\u7684\u54a8\u8be2\u65b9\u6848\u5404\u65b9\u9762\u7684\u5185\u5bb9\uff1b\n(3)\u5c0a\u91cd\u54a8\u8be2\u5e08\uff0c\u9075\u5b88\u65f6\u95f4\uff0c\u5982\u6709\u7279\u6b8a\u60c5\u51b5\u63d0\u524d\u544a\u77e5\u54a8\u8be2\u5e08\u3002\n         \u5341\u4e8c\u3001\u54a8\u8be2\u5e08\u7684\u8d23\u4efb\u6743\u529b\u4e49\u52a1\n\u8d23\u4efb\uff1a\n(1)\u3001\u54a8\u8be2\u5e08\u5728\u4ece\u4e8b\u5fc3\u7406\u54a8\u8be2\u4e0e\u6cbb\u7597\u65f6\uff0c\u5e94\u9075\u7eaa\u5b88\u6cd5\u3001\u9075\u5b88\u54a8\u8be2\u5e08\u9053\u5fb7\u51c6\u5219\uff0c\u5728\u5176\u5de5\u4f5c\u4e2d\u5efa\u7acb\u5e76\u6267\u884c\u4e25\u683c\u7684\u9053\u5fb7\u6807\u51c6\uff1b\n(2)\u3001\u54a8\u8be2\u5e08\u5e94\u6ce8\u610f\u52a0\u5f3a\u81ea\u8eab\u7684\u4fee\u517b\uff0c\u4e0d\u65ad\u5b8c\u5584\u81ea\u5df1\uff0c\u63d0\u9ad8\u81ea\u5df1\u7684\u5fc3\u7406\u5065\u5eb7\u6c34\u5e73\uff1b\n(3)\u3001\u54a8\u8be2\u5e08\u5e94\u4e0d\u65ad\u5b66\u4e60\u672c\u4e13\u4e1a\u7684\u6709\u5173\u77e5\u8bc6\uff0c\u901a\u8fc7\u4e0d\u65ad\u6539\u5584\u81ea\u8eab\u7684\u5de5\u4f5c\u5b9e\u8df5\u3001\u6559\u5b66\u548c\u79d1\u7814\u6c34\u5e73\uff0c\u4ee5\u4fc3\u8fdb\u81ea\u8eab\u7684\u4e13\u4e1a\u53d1\u5c55\uff0c\u63d0\u9ad8\u4e13\u4e1a\u670d\u52a1\u6c34\u5e73\uff1b\n(4)\u3001\u54a8\u8be2\u5e08\u5e94\u660e\u786e\u4e86\u89e3\u81ea\u5df1\u7684\u80fd\u529b\u754c\u9650\u548c\u4e13\u4e1a\u804c\u80fd\u7684\u754c\u9650\uff0c\u4e0d\u505a\u8d85\u8d8a\u81ea\u5df1\u80fd\u529b\u548c\u804c\u80fd\u8303\u56f4\u7684\u4e8b\u60c5\uff1b\n(5)\u3001\u54a8\u8be2\u5e08\u4e0d\u5f97\u56e0\u6765\u8bbf\u8005\u7684\u6027\u522b\u3001\u6c11\u65cf\u3001\u56fd\u7c4d\u3001\u5b97\u6559\u4fe1\u4ef0\u3001\u4ef7\u503c\u89c2\u7b49\u4efb\u4f55\u65b9\u9762\u7684\u56e0\u7d20\u6b67\u89c6\u6765\u8bbf\u8005\uff1b\n(6)\u3001\u54a8\u8be2\u5e08\u5728\u6cbb\u7597\u5173\u7cfb\u5efa\u7acb\u4e4b\u524d\uff0c\u5e94\u4f7f\u6765\u8bbf\u8005\u660e\u786e\u4e86\u89e3\u5fc3\u7406\u54a8\u8be2\u4e0e\u6cbb\u7597\u5de5\u4f5c\u7684\u6027\u8d28\u3001\u5de5\u4f5c\u7279\u70b9\u3001\u6536\u8d39\u6807\u51c6\u548c\u8fd9\u4e00\u5de5\u4f5c\u53ef\u80fd\u7684\u5c40\u9650\u4ee5\u53ca\u6765\u8bbf\u8005\u7684\u6743\u5229\u548c\u4e49\u52a1\uff1b\n(7)\u3001\u54a8\u8be2\u5e08\u5728\u5bf9\u6765\u8bbf\u8005\u8fdb\u884c\u5de5\u4f5c\u65f6\uff0c\u5e94\u4e0e\u6765\u8bbf\u8005\u5bf9\u5de5\u4f5c\u91cd\u70b9\u8fdb\u884c\u8ba8\u8bba\u5e76\u8fbe\u6210\u4e00\u81f4\u610f\u89c1\uff0c\u5fc5\u8981\u65f6\uff08\u5982\u8fdb\u884c\u5b9e\u5730\u51b2\u51fb\u7597\u6cd5\uff09\u5e94\u4e0e\u6765\u8bbf\u8005\u8fbe\u6210\u4e66\u9762\u534f\u8bae\uff1b\n(8)\u3001\u54a8\u8be2\u5e08\u5e94\u660e\u786e\u5176\u5de5\u4f5c\u7684\u76ee\u7684\u662f\u4fc3\u8fdb\u6765\u8bbf\u8005\u7684\u6210\u957f\u3001\u81ea\u5f3a\u81ea\u7acb\uff0c\u800c\u5e76\u975e\u4f7f\u6765\u8bbf\u8005\u5728\u5176\u672a\u6765\u7684\u751f\u6d3b\u4e2d\u5bf9\u5fc3\u7406\u533b\u751f\u4ea7\u751f\u4f9d\u8d56\u3002\n\u6743\u529b\uff1a\n(1)\u6709\u6743\u529b\u4e86\u89e3\u4e0e\u6c42\u52a9\u8005\u5fc3\u7406\u95ee\u9898\u6709\u5173\u7684\u4e2a\u4eba\u8d44\u6599\uff1b\n(2)\u6709\u6743\u529b\u9009\u62e9\u5408\u9002\u7684\u6c42\u52a9\u8005\uff1b\n(3)\u672c\u7740\u5bf9\u6c42\u52a9\u8005\u8d1f\u8d23\u7684\u6001\u5ea6\uff0c\u6709\u6743\u529b\u63d0\u51fa\u8f6c\u4ecb\u6216\u8005\u4e2d\u6b62\u54a8\u8be2\u3002\n\u4e49\u52a1\uff1a\n(1)\u5411\u6c42\u52a9\u8005\u4ecb\u7ecd\u81ea\u5df1\u7684\u53d7\u8bad\u80cc\u666f\uff1b\n(2)\u9075\u5b88\u54a8\u8be2\u673a\u6784\u7684\u6709\u5173\u89c4\u5b9a\uff1b\n(3)\u9075\u5b88\u548c\u6267\u884c\u5546\u5b9a\u597d\u7684\u54a8\u8be2\u65b9\u6848\u5404\u65b9\u9762\u7684\u5185\u5bb9\u3002\n         \u5341\u4e09\u3001\u53cc\u65b9\u5171\u540c\u9075\u5b88\u4e0a\u8ff0\u6761\u6b3e\uff0c\u7528\u6237\u5728\u5e73\u53f0\u5185\u4f7f\u7528\u5e73\u53f0\u63d0\u4f9b\u7684\u9884\u7ea6\u54a8\u8be2\u670d\u52a1\uff0c\u5e76\u52fe\u9009\u4e86\u9605\u8bfb\u5e76\u540c\u610f\u672c\u534f\u8bae\u7684\u9009\u9879\uff0c\u5373\u89c6\u4e3a\u540c\u610f\u672c\u534f\u8bae\u7684\u5168\u90e8\u5185\u5bb9\u3002"}',
                    'explain' => '咨询设置',
                    'time' => $time
                ], [
                    'unit_id' => $unit_id,
                    'key' => 'interfere_manual',
                    'value' => '"'.env('SETTING.INTERVENTION_HANDBOOK').'"',
                    'explain' => '危机干预手册',
                    'time' => $time
                ], [
                    'unit_id' => $unit_id,
                    'key' => 'soft_setting',
                    'value' => '{"news_center":"1","news_type":["1","2","3","4","5","6"],"data_board":"1","enter_board":["1"],"board_verfied":"1","home_todo":["1","2","3","4"],"web_url":"1","screen_protect":"1","is_mobile":"1"}',
                    'explain' => '软件设置',
                    'time' => $time
                ], [
                    'unit_id' => $unit_id,
                    'key' => 'screen_setting',
                    'value' => '[{"id":"25","dot":"1","x":"40","y":"105"},{"id":"26","dot":"1","x":"560","y":"105"},{"id":"27","dot":"1","x":"967","y":"105"},{"id":"28","dot":"1","x":"1380","y":"105"},{"id":"29","dot":"1","x":"40","y":"530"},{"id":"30","dot":"1","x":"560","y":"565"},{"id":"31","dot":"1","x":"1380","y":"460"},{"id":"35","dot":"1","x":"560","y":"320"}]',
                    'explain' => '数据大屏设置',
                    'time' => $time
                ]
            ];
            $ConfigModel = new ConfigModel();
            $ConfigModel->insertAll($data);
            return true;
        } catch (\Exception $e) {
            $this->message = $e->getMessage();
            $this->line = $e->getLine();
            return false;
        }
    }

}
